using System;
using FarseerPhysics;
using FarseerPhysics.Samples.Demos;
using JilyGameFramework.Controls;
using JilyGameFramework.Datas;
using JilyGameFramework.Manager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace WindowsGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class MainGame : Microsoft.Xna.Framework.Game
    {
        public GraphicsDeviceManager Graphics { get; private set; }
        SpriteBatch spriteBatch;

        public ScreenManager ScreenManager { get; set; }

        public MainGame()
        {
            Graphics = new GraphicsDeviceManager(this);

            Graphics.IsFullScreen = false;
            Graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            Graphics.PreferMultiSampling = true;

            Graphics.PreferredBackBufferWidth = GlobalData.DefaultWidth;
            Graphics.PreferredBackBufferHeight = GlobalData.DefaultHeight;
            //   ConvertUnits.SetDisplayUnitToSimUnitRatio(16f);
            IsFixedTimeStep = false;

            Content.RootDirectory = "Content";

            ScreenManager = new ScreenManager(this);
            Components.Add(ScreenManager);

            //var a = ScreenManager.GraphicsDevice.Viewport;

            //FrameRateCounter frameRateCounter = new FrameRateCounter(ScreenManager);
            //frameRateCounter.DrawOrder = 101;
            //Components.Add(frameRateCounter);
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            Button button = new Button(new Rectangle(100, 100, 70, 70), "Common/stick", "Common/socket");
            ScreenManager.AddScreen(button);


            AdvancedDemo1 a1 = new AdvancedDemo1();
            ScreenManager.AddScreen(a1);

            //SimpleDemo1 simple1 = new SimpleDemo1();
            //SimpleDemo2 simple2 = new SimpleDemo2();
            //SimpleDemo3 simple3 = new SimpleDemo3();
            //SimpleDemo4 simple4 = new SimpleDemo4();
            //SimpleDemo5 simple5 = new SimpleDemo5();
            //SimpleDemo6 simple6 = new SimpleDemo6();
            //SimpleDemo7 simple7 = new SimpleDemo7();
            //SimpleDemo8 simple8 = new SimpleDemo8();
            //SimpleDemo9 simple9 = new SimpleDemo9();

            //AdvancedDemo1 advanced1 = new AdvancedDemo1();
            //AdvancedDemo2 advanced2 = new AdvancedDemo2();
            //AdvancedDemo3 advanced3 = new AdvancedDemo3();
            //AdvancedDemo4 advanced4 = new AdvancedDemo4();
            //AdvancedDemo5 advanced5 = new AdvancedDemo5();

            //GameDemo1 game1 = new GameDemo1();

            //MenuScreen menuScreen = new MenuScreen("Farseer Samples");

            //menuScreen.AddMenuItem("Simple Samples", EntryType.Separator, null);
            //menuScreen.AddMenuItem(simple1.GetTitle(), EntryType.Screen, simple1);
            //menuScreen.AddMenuItem(simple2.GetTitle(), EntryType.Screen, simple2);
            //menuScreen.AddMenuItem(simple3.GetTitle(), EntryType.Screen, simple3);
            //menuScreen.AddMenuItem(simple4.GetTitle(), EntryType.Screen, simple4);
            //menuScreen.AddMenuItem(simple5.GetTitle(), EntryType.Screen, simple5);
            //menuScreen.AddMenuItem(simple6.GetTitle(), EntryType.Screen, simple6);
            //menuScreen.AddMenuItem(simple7.GetTitle(), EntryType.Screen, simple7);
            //menuScreen.AddMenuItem(simple8.GetTitle(), EntryType.Screen, simple8);
            //menuScreen.AddMenuItem(simple9.GetTitle(), EntryType.Screen, simple9);

            //menuScreen.AddMenuItem("Advanced Samples", EntryType.Separator, null);
            //menuScreen.AddMenuItem(advanced1.GetTitle(), EntryType.Screen, advanced1);
            //menuScreen.AddMenuItem(advanced2.GetTitle(), EntryType.Screen, advanced2);
            //menuScreen.AddMenuItem(advanced3.GetTitle(), EntryType.Screen, advanced3);
            //menuScreen.AddMenuItem(advanced4.GetTitle(), EntryType.Screen, advanced4);
            //menuScreen.AddMenuItem(advanced5.GetTitle(), EntryType.Screen, advanced5);

            //menuScreen.AddMenuItem("Game Samples", EntryType.Separator, null);
            //menuScreen.AddMenuItem(game1.GetTitle(), EntryType.Screen, game1);

            //menuScreen.AddMenuItem("", EntryType.Separator, null);
            //menuScreen.AddMenuItem("Exit", EntryType.ExitItem, null);

            //ScreenManager.AddScreen(new BackgroundScreen(GlobalDatas.Logo, GlobalDatas.Background));
            ////ScreenManager.AddScreen(menuScreen);

            //Button button = new Button(new Rectangle(100, 100, 70, 70), "Common/stick", "Common/socket");
            //ScreenManager.AddScreen(button);
            //ScreenManager.AddScreen(new LogoScreen(GlobalDatas.ViewImage, TimeSpan.FromSeconds(3.0)));

            //ScreenManager.AddScreen(advanced1);
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }
    }
}
